

clear all

set more off 


***************************************

global estimators xtreg

*is it onset (=1) or incidence(=.)?
local cheat 1

if "`cheat'" == "." {
	local on_or_in incidence
}
if "`cheat'" == "1" {
	local on_or_in onset
}

***************************************
***************************************

*Version 1: with topics

***plotting
local title_left Civil War
local title_right Armed Conflict

local left_solid_name Overall Model
local left_dash_name Within Model

local right_solid_name Overall Model
local right_dash_name Within Model

clear
use model_names
levelsof controls, local(levels) 
clear



*version 2: without topics but rainfall
*global estimators xtreg xtlogit clogit
global estimators xtreg

*is it onset (=1) or incidence(=.)?
local cheat 1

if "`cheat'" == "." {
	local on_or_in incidence
}
if "`cheat'" == "1" {
	local on_or_in onset
}


***plotting
local title_left Civil War
local title_right Armed Conflict

local left_solid_name Overall Model
local left_dash_name Within Model

local right_solid_name Overall Model
local right_dash_name Within Model

clear
use model_names
levelsof controls, local(levels) 
clear


*foreach on_or_in in onset incidence {

foreach on_or_in in onset {

*forval p = 1 / 2 {
foreach q in a b {

if "`q'" == "a" {
	local what civilwar
	local p 1
}
if "`q'" == "b" {
	local what armedconflict
	local p 2

}

foreach j in controls {	

	foreach x in $estimators {

		display "`j'"
		display "`k'"
		display "`x'"

		clear

			*graph of war
		use output/for_roc_`on_or_in'`p'

		rename modelname model
		sort model
		merge model using model_names
		sort id fpr tpr
			
		

		graph drop _all
			
		local l = 1
			
		foreach k of local levels {
		
			local doit 0
		
			if "`k'" == "fixedeffect"  {
				local nameit Fixed effect
				local doit 1
				local num 6
			}
			if "`k'" == "chadefaux"  {
				local nameit Keyword Count
				local doit 1
				local num 5
			}
			if "`k'" == "ajps"  {
				local nameit Economics and Political
				local doit 1
				local num 3
			}
			if "`k'" == "ward"  {
				local nameit Events
				local doit 1
				local num 4
			}
			if "`k'" == "pillars"  {
				local nameit Shocks and Institutions
				local doit 1
				local num 2
			}
			if "`k'" == "rain"  {
				local nameit Rainfall
				local doit 1
				local num 1
			}
			

			

			sum auc if what == "overall" & init == "`j'" & controls == "`k'" & estimation == "`x'"
			if `r(N)' > 0 & `doit' == 1 {
				local auc1 = substr(string(round(`r(max)',.01)), 1, 3)
				sum auc if what == "within" & init == "`j'" & controls == "`k'" & estimation == "`x'"
				local auc2 = substr(string(round(`r(max)',.01)), 1, 3)

				twoway (line tpr fpr if what == "overall" & init == "`j'" & controls == "`k'" & estimation == "`x'", lwidth(medthick)  lpattern(solid)  sort) ///
				(line tpr fpr if what == "within" & init == "`j'" & controls == "`k'" & estimation == "`x'", lwidth(medthick) lpattern(dash)  sort) ///
				 (line fpr fpr if what == "overall" & init == "`j'" & controls == "`k'" & estimation == "`x'", color(gs10) lpattern(dash) sort), ///
				subtitle("`nameit'", color(black)) ytitle("") xtitle("") legend( order(1 "`left_solid_name'" 2 "`left_dash_name'") size(small)) xlabel(,grid) ///
				plotregion(fcolor(white)) graphregion(fcolor(white))  aspectratio(1) ///	
				caption( "AUC: Overall `auc1', Within `auc2'", size(medium) color(black) ring(0)  placement(se)) ///
				name(fig`num')


				local l = `l' + 1
				
			}


		}
		
				
		grc1leg fig1 fig2 fig3 fig4 fig5 fig6 , legendfrom(fig1) title("", color(black)  size(small)) subtitle("", color(black) size(small)) plotregion(fcolor(white)) graphregion(fcolor(white)) 

		*graph export output/alltogether_`x'_`on_or_in'_`what'_notopics.eps ,replace
		graph export output/fig1`q'.eps ,replace
		
	}
}



}

}





